<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/css/template.css" rel="stylesheet" type="text/css" />
<title>Show Phone Repair Status For Shop</title>
<?php echo Model_Cnotice::css('2014-11-10');?>
<style>
.emergency {
	background-color: red;
}
</style>
</head>
<?php
$insstr1 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#FFFF00; border-style:solid; border-width:1px;">A</td>
    <td>Waiting For HQ Pick Up</td>
  </tr>
</table>
';
$insstr2 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#00B0F0; border-style:solid; border-width:1px;">B</td>
    <td>In Transit (Shop to HQ)</td>
  </tr>
</table>
';
$insstr3 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#FFC000; border-style:solid; border-width:1px;">C</td>
    <td>Before Quote</td>
  </tr>
</table>
';
$insstr4 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#92D050; border-style:solid; border-width:1px;">D</td>
    <td>After Quote</td>  
  </tr>
</table>
';
$insstr5 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#E6B8B7; border-style:solid; border-width:1px;">E</td>
    <td>Phone Fixed / Phone Can\'t Fix</td>
  </tr>
</table>
';
$insstr6 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#00B0F0; border-style:solid; border-width:1px;">F</td>
    <td>In Transit (HQ to Shop)</td>
  </tr>
</table>
';
$insstr7 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#BFBFBF; border-style:solid; border-width:1px;">G</td>
    <td>In Store, Waiting Customer Pickup</td>
  </tr>
</table>
';
$insstr8 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#FFFFFF; border-style:solid; border-width:1px;">H</td>
    <td>Pick Up, Case Closed.</td>  
  </tr>
</table>
';

//2014-07-18
$insstr9 = '
<table width="230" border="0" cellspacing="10" cellpadding="0">
	<tr>
		<td style="width:16px; border-color:#333; background-color:red; border-style:solid; border-width:1px;">I</td>
		<td>Emergency Job.</td>
	</tr>
</table>
';

$rCenterMapping = $this->rCenterMapping;
$shopHead = $this->shophead;
$idShop = $rCenterMapping[$shopHead];


?>


<body>
<?php echo Model_Cnotice::content('2014-11-10', '20141110editJob.jpg');
	  $rProducts = new Model_DbTable_Pr_Prproducts();
	  $rBorrow = new Model_DbTable_Pr_Loan();
	  $lastStatusList = new Model_DbTable_Repairstatusrecord();
	  $newStatus = new Model_DbTable_Jobstatus();
	  $sDetail = new Model_DbTable_Roster_Stafflogindetail();
	  $rStock = new Model_DbTable_Pr_Prstockmovement();
	  $commentRecords = new Model_DbTable_Jobcomments();?>
<h1><?php echo $this->shophead;?> | <a href="/repaircenter/mainpage/shop/<?php echo $this->shophead;?> ">Back to Main Page</a></h1>
<form id="form1" name="form1" method="post" action="/repaircenter/showstatusbyjobid">
       <input type="text" name="id_job" id="id_job" style="width:250px;" />
       <input type="hidden" name="shop_head" id="shop_head" value="<?php echo $this->shophead;?>" />
       <input type="submit" name="go" id="go" value="GO TO THIS JOBID" />
</form>

<h3>Status List:</h3>
<table width="1000" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td style="width:16px; border-color:#333; background-color:#FFFF00; border-style:solid; border-width:1px;">A</td>
    <td>Waiting For HQ Pick Up</td>
    <td style="width:16px; border-color:#333; background-color:#00B0F0; border-style:solid; border-width:1px;">B</td>
    <td>In Transit (Shop to HQ)</td>
    <td style="width:16px; border-color:#333; background-color:#FFC000; border-style:solid; border-width:1px;">C</td>
    <td>Before Quote</td>
    <td style="width:16px; border-color:#333; background-color:#92D050; border-style:solid; border-width:1px;">D</td>
    <td>After Quote</td>        
  </tr>
  <tr>
    <td style="width:16px; border-color:#333; background-color:#E6B8B7; border-style:solid; border-width:1px;">E</td>
    <td>Phone Fixed / Phone Can't Fix</td>
    <td style="width:16px; border-color:#333; background-color:#00B0F0; border-style:solid; border-width:1px;">F</td>
    <td>In Transit (HQ to Shop)</td>
    <td style="width:16px; border-color:#333; background-color:#BFBFBF; border-style:solid; border-width:1px;">G</td>
    <td>In Store, Waiting Customer Pickup</td>
    <td style="width:16px; border-color:#333; background-color:#FFFFFF; border-style:solid; border-width:1px;">H</td>
    <td>Pick Up, Case Closed.</td>
    <td style="width:16px; border-color:#333; background-color:red; border-style:solid; border-width:1px;">I</td>
    <td>Emergency Job.</td>            
  </tr>
</table>
<form id = "form2" method = "post" action = "" enctype="multipart/form-data">

<table width="1150"  cellspacing="0" cellpadding="1" style="border:#06C solid 1px;">
  <tr>
    <td style="width:150px;" class="thetbheader">Job ID</td>
    <td style="width:180px;" class="thetbheader">Mobile</td>
    <td style="width:180px;" class="thetbheader">Customer Contacts</td>
    <td colspan="2" align="center" class="thetbheader" style="width:240px;">Status</td>
    <td align="center" style="width:150px;" class="thetbheader">Repair By</td>
    <td style="width:80px;"class="thetbheader" >Last Update</td>
    <td colspan="3" align="center" valign="middle" class="thetbheader">Actions</td>
  </tr>
<?php 

if(empty($this->searchresult)){
?>
<tr>
	<td colspan="14"> No record at the moment</td>
</tr>
<?php	
	}
else{
$counter = 0;	

foreach($this->searchresult as $k=>$v){
$theLastStatus = $lastStatusList->getLastStatus($v['id_job']);
$statusCheck = $lastStatusList->getStatusList($v['id_job']);
$check = 0;
foreach($statusCheck as $k2 => $v2){
	if($v2['id_status'] == 36 && $theLastStatus[0]['id_status'] < 90){
		$check++;
	}
}
if($theLastStatus[0]['id_status'] == $v['id_status'] and $theLastStatus[0]['time_record'] == $v['time_record'] && $v['is_qf'] != 1){	
?>
  <tr
  <?php 
  if($check != 0){
  	echo 'class = "emergency"';
  }
  if($counter%2 ==1 ){ 
  echo 'class="thelineback"';
  }

  $counter++;
  ?>
  >
  
    <td><?php echo $v['id_job'];?><a href="/repaircenter/edit/jobId/<?php echo $v['id_job'];?>" target="_blank"><img src="/css/edit.gif" /></a><input type="hidden" name="id_job2[<?php echo $k;?>]" id="id_job2_<?php echo $k;?>" value="<?php echo $v['id_job']?>"></input></td>
    <td><?php echo $v['mobile_brand']." ".$v['mobile_model']; ?></td>
    <td><?php echo $v['customer_name'];?><a href="/repairjob/<?php echo $this->shophead; ?>/<?php echo $v['id_job'];?>.html" style="font-size:12px;" target="_blank"><img src="/im/icon_print.gif" /></a></td>
    <td style="width:230px;">	
	[<?php echo $v['id_status'];?>]
    <?php
    
	echo $newStatus->getStatusDes($v['id_status']);
	?>	
    <?php
	if($v['id_status'] == 1 or $v['id_status'] == 3 or $v['id_status'] == 5 or $v['id_status'] == 7  ){ echo $insstr1;}
	if($v['id_status'] == 8 or $v['id_status'] == 9 ){ echo $insstr2;}
	if($v['id_status'] == 12 or $v['id_status'] == 14 or $v['id_status'] == 16 ){ echo $insstr3;}
	if($v['id_status'] == 18 or $v['id_status'] == 20 or $v['id_status'] == 22 or $v['id_status'] == 24  ){ echo $insstr4;}
	if($v['id_status'] == 23 or $v['id_status'] == 25 or $v['id_status'] == 29 ){ echo $insstr5;}
	if($v['id_status'] == 26 or $v['id_status'] == 27 ){ echo $insstr6;}
	if($v['id_status'] == 28 or $v['id_status'] == 30 ){ echo $insstr7;}
	if($v['id_status'] == 80 or $v['id_status'] == 90 ){ echo $insstr8;}
	//2014-07-18
	$dateToday = date_default_timezone_set('Australia/Melbourne');
	$dateTest = date('Y/m/d', time());
	$dateCheck = Model_DatetimeHelper::dateDiff($dateTest,$theLastStatus[0]['time_record']);
	$dateCheck += 1;
	if($v['id_status'] == 36){echo $insstr9.'Emergency last days:('.$dateCheck.')'.' Update by:'.$theLastStatus[0]['staff_record'];}
	?>
 
    </td>
    <td style="width:10px;"><a href="/repaircenter/viewhistory/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;" target="_blank"><img src="/css/details.gif" /></a>&nbsp; 
      <a href="/repaircenter/check-tracking-info/id_job/<?php echo $v['id_job'];?>"><img src="/css/tracking_small.jpg" border="0" title="Show Tracking Information Of The JOB" /></a>
    </td>
    <td align="center" style="width:10px;">
   <?php  if($v['repair_staff'] == 0 || $v['repair_staff'] == null ){ ?>
	<a href="/repaircenter/add-repair-staff/jobid/<?php echo $v['id_job'];?>" target="_blank" > Add Repair Staff </a>
	<input type = "hidden" name = "repair_staff[<?php echo $k;?>]" id = "repair_staff_<?php echo $k;?>" value = ""></input>
   <?php }
   else{
	
	$stLine = $sDetail->getDetail($v['repair_staff']);
	echo ucwords($stLine["ni"]).".".chr($stLine["il"]+64);?>
	<input type = "hidden" name = "repair_staff[<?php echo $k;?>]" id = "repair_staff_<?php echo $k;?>" value = "<?php echo ucwords($stLine["ni"]);?>"></input>
	<?php 
	  }
    ?>
    
    </td>
    <td align="center"><?php echo $v['time_record'];?></td>
    <td align="center" valign="middle"><a href="/repaircenter/close-job-wizard/jobid/<?php echo $v['id_job'];?>/shop/<?php echo $shopHead?>" style="font-size:12px;" target="_blank"><img src="/css/edit.gif" />
Status</a></td>
    <?php /*?>
    <td align="center" valign="middle"><a href="/repaircenter/changestatusshop/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;" target="_blank"><img src="/css/edit.gif" />
Status</a></td>
    <td align="center" valign="middle"><a href="/repaircenter/changequote/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;"  target="_blank" ><img src="/css/edit.gif" />
Quote</a></td>
    <td align="center" valign="middle"><a href="/repaircenter/updateinvoice/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;"  target="_blank"><img src="/css/edit.gif" />
Invoice</a></td> */?>
    <td align="center" valign="middle">
    <?php
    if($idShop!=99){
	?>
      <a target="_blank" href="/repairparts/parts-record-with-borrow/shophead/<?php echo $this->shophead;?>/shop/<?php echo $idShop;?>/jobid/<?php echo $v['id_job'];?>">
      Parts<br />
      Record</a>
      <?php }?>
      </td>
    <?php /*?>
    <td align="center" valign="middle" style="padding:5px;">
    
    <?php 
	$model = $v['mobile_model'];
	if($model == "iPod Touch 3" || $model=="iPod Touch 4" || $model=="iPod Touch 5" || $model=="iPod Touch 6" || $model=="iPad 2" || $model=="iPad 3" || $model=="iPad 4" || $model=="iPad 5" || $model=="iPad Mini"  || $model=="iPad Air"  ){
	echo "NO-NEED<br/>IMEI";	
	}
	else{
	?>
    <a href="/repaircenter/update-imei/idjob/<?php echo $v['id_job'];?>" target="_blank">*#06#<br />
    IMEI</a>
    <?php }?>
    </td> */ ?>
    <td><input type = 'submit' name = 'emergency_button[<?php echo $k;?>]' id = 'emergency_button_<?php echo $k;?>' value = 'Emergency Job' style = "background-color: red" onclick="if(confirm('Change to emergency job?')){} else {return false;};"></input></td>
  </tr>
    <tr>
    <td colspan="1" style="height:40px;">
    Part(s) Record On:<br />
    <?php
    
	$tmprows = $rStock->getPartsRecordByJobId($v['id_job']);
	if(isset($tmprows) && count($tmprows) > 0){
		//var_dump($tmprows);
		echo $tmprows[0]['date_move'];
		}
	else{
		echo "NoRecord";
		}	
	?>
    </td>
    <td colspan="12" style="border:#666 1px solid;">
    <?php
	
	
 	if(isset($tmprows) && count($tmprows) > 0){
		//var_dump($tmprows);
		foreach($tmprows as $key => $value){
			
			$rowProduct = $rProducts->getProduct($value['id_product']);
			echo "[".$rowProduct['code_product']."] ".$rowProduct['title_product']." ";
			if($value['code_move'] == 2){
				echo "x ";
				}
			elseif($value['code_move'] == 7){
				echo "x -";
				}	
			
			echo $value['qty_product'];
			
			$bLine = $rBorrow->getByStMoveCode($value['id_move']);
			
			if($bLine){
				
				echo " Borw Code :[<a href=\"/repairparts/confirm-borrow/bcode/{$bLine['b_code']}\" target=\"_blank\">{$bLine['b_code']}</a>] ";
				
				echo ($bLine['confirmed'])?"<span style=\"color:#0f0;\" title = \"Borrow Action Confirmed By Other Party,Stock Has Been Adjusted\">Confirmed</span>":"<span style=\"color:#f00;\" title = \"Borrow Action Hasn't Been Confirmed By Other Party,Stock Has Not Been Adjusted YET\" >Not Confirm Yet</span>";
				
				}
			echo "<br />";	
			}	
		}   
	?>
    
    </td>
  </tr>
  <tr>
  <td colspan="1" style="height:40px;">
  Comment<a href="/repaircenter/viewdetailstatus/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;" target="_blank" ><img src="/css/details.gif" /></a><br />
  [<?php echo $v['id_job'];?>]:
  </td>  
  <td colspan="12" style="border:#666 1px solid;">
  <?php
  		
		$commentList = $commentRecords->listCommentByJobID($v['id_job']);	
  if(isset($commentList)){
	  foreach($commentList as $k1 =>$v1){
	?>	  
		  Comment by [<?php echo $v1['staffname_repair_comt']?>] on <?php echo $v1['date_repair_comt']?>,<?php echo $v1['time_repair_comt']?> <br /><div style=" border:#666 1px solid;"><?php echo $v1['content_repair_comt']?></div>
	<?php	  
		  }	  
	  } 
  ?>
  </td>
  </tr>

<?php
}
}
}
?>
</table>

<?php if(!empty($this->quickJobs)){
		$counter = 0;?>
<h2>Simple Job List</h2><br/>
	<table width="1150"  cellspacing="0" cellpadding="1" style="border:#06C solid 1px;">
  <tr>
    <td style="width:150px;" class="thetbheader">Job ID</td>
    <td style="width:180px;" class="thetbheader">Mobile</td>
    <td style="width:180px;" class="thetbheader">Customer Contacts</td>
    <td align="center" class="thetbheader" style="width:240px;">Status</td>
    <td align="center" style="width:150px;" class="thetbheader">Repair By</td>
    <td style="width:80px;"class="thetbheader" >Last Update</td>
    <td colspan="2" align="center" valign="middle" class="thetbheader">Actions</td>
  </tr>
  
	<?php foreach($this->quickJobs as $k => $v){ ?>
	
	<tr <?php if($counter%2 ==1 ){ 
  			echo 'class="thelineback"';
  		}

  $counter++;?>>
		<td><?php echo $v['id_job']?><a href="/repaircenter/edit/jobId/<?php echo $v['id_job'];?>" style="font-size:12px;" target="_blank"><br/>(Normal Job)</a></td>
		<td><?php echo $v['mobile_brand']." ".$v['mobile_model']?></td>
		<td><?php echo $v['customer_name']?><a href="/repairjob/<?php echo $this->shophead; ?>/<?php echo $v['id_job'];?>.html" style="font-size:12px;" target="_blank"><img src="/im/icon_print.gif" /></a></td>
		<td><?php echo $newStatus->getStatusDes($v['id_status']);?></td>
		<td><?php  if($v['repair_staff'] == 0 || $v['repair_staff'] == null ){ ?>
			<a href="/repaircenter/add-repair-staff/jobid/<?php echo $v['id_job'];?>" target="_blank" >Sale/Repair Staff</a>
			<?php }else{
					$stLine = $sDetail->getDetail($v['repair_staff']);
					echo ucwords($stLine["ni"]).".".chr($stLine["il"]+64);?>
			<?php }?></td>
		<td align="center"><?php echo $v['time_record'];?></td>
		<td align="center" valign="middle"><a href="/repaircenter/close-job-wizard/jobid/<?php echo $v['id_job'];?>/shop/<?php echo $shopHead?>" style="font-size:12px;" target="_blank"><img src="/css/edit.gif" />
Status</a></td>
		<?php /*
		<td align="center" valign="middle"><a href="/repaircenter/changestatusshop/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;" target="_blank"><img src="/css/edit.gif" />
			Status</a></td>
    	<td align="center" valign="middle"><a href="/repaircenter/updateinvoice/jobid/<?php echo $v['id_job'];?>" style="font-size:12px;"  target="_blank"><img src="/css/edit.gif" />
			Invoice</a></td>
			*/ ?>
		<td align="center" valign="middle">
    		<?php if($idShop!=99){?>
      			<a target="_blank" href="/repairparts/parts-record-with-borrow/shophead/<?php echo $this->shophead;?>/shop/<?php echo $idShop;?>/jobid/<?php echo $v['id_job'];?>">
      			Parts<br />Record</a>
      		<?php }?>
        </td>
        <?php /*
		<td align="center" valign="middle" style="padding:5px;">
    
    		<?php 
				$model = $v['mobile_model'];
				if($model == "iPod Touch 3" || $model=="iPod Touch 4" || $model=="iPod Touch 5" || $model=="iPod Touch 6" || $model=="iPad 2" || $model=="iPad 3" || $model=="iPad 4" || $model=="iPad 5" || $model=="iPad Mini"  || $model=="iPad Air"  ){
					echo "NO-NEED<br/>IMEI";	
				}else{?>
    				<a href="/repaircenter/update-imei/idjob/<?php echo $v['id_job'];?>" target="_blank">*#06#<br />IMEI</a>
    		   <?php }?>
    	</td> */ ?>
	</tr>
	<tr>
    <td colspan="1" style="height:40px;">
    Part(s) Record On:<br />
    <?php
    
	$tmprows = $rStock->getPartsRecordByJobId($v['id_job']);
	if(isset($tmprows) && count($tmprows) > 0){
		//var_dump($tmprows);
		echo $tmprows[0]['date_move'];
		}
	else{
		echo "NoRecord";
		}	
	?>
    </td>
    <td colspan="12" style="border:#666 1px solid;">
    <?php
	
	
 	if(isset($tmprows) && count($tmprows) > 0){
		//var_dump($tmprows);
		foreach($tmprows as $key => $value){
			
			$rowProduct = $rProducts->getProduct($value['id_product']);
			echo "[".$rowProduct['code_product']."] ".$rowProduct['title_product']." ";
			if($value['code_move'] == 2){
				echo "x ";
				}
			elseif($value['code_move'] == 7){
				echo "x -";
				}	
			
			echo $value['qty_product'];
			
			$bLine = $rBorrow->getByStMoveCode($value['id_move']);
			
			if($bLine){
				
				echo " Borw Code :[<a href=\"/repairparts/confirm-borrow/bcode/{$bLine['b_code']}\" target=\"_blank\">{$bLine['b_code']}</a>] ";
				
				echo ($bLine['confirmed'])?"<span style=\"color:#0f0;\" title = \"Borrow Action Confirmed By Other Party,Stock Has Been Adjusted\">Confirmed</span>":"<span style=\"color:#f00;\" title = \"Borrow Action Hasn't Been Confirmed By Other Party,Stock Has Not Been Adjusted YET\" >Not Confirm Yet</span>";
				
				}
			echo "<br />";	
			}	
		}   
	?>
    
    </td>
  </tr>
		<?php }?>
  </table>	

<?php }?>
</form>
<br/>
<div style=" font-size:10px; color:#666;float:right;" >Developer:Leo,Date:2015-07-09,,ver:1.02</div>
</body>

</html>
